package com.o2o.app.userCenter;

/**
 * 我的消息
 */
import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.o2o.app.R;
import com.o2o.app.adapter.MessageListAdapter;
import com.o2o.app.bean.MessageBean;
import com.o2o.app.views.RefreshListView;
import com.o2o.app.views.RefreshListView.ILoadMoreViewState;
import com.o2o.app.views.RefreshListView.IOnLoadMoreListener;
import com.o2o.app.views.RefreshListView.IOnRefreshListener;

public class MineMessageActivity extends Activity implements
		IOnRefreshListener, IOnLoadMoreListener, OnItemClickListener {
	/**
	 * 回复我的按钮
	 */
	private RelativeLayout rlt_01;

	/**
	 * 系统消息
	 */
	private RelativeLayout rlt_02;

	/**
	 * 回复我的文字
	 */
	private TextView tv_01, tv_02;
	private ImageView iv_huaxian1, iv_huaxian2;

	/**
	 * 返回
	 */
	private Button btn_back;

	/**
	 * 回复我的
	 */
	private RefreshListView rlv_comment;

	/**
	 * 系统消息
	 */
	private RefreshListView rlv_system;

	private ArrayList<MessageBean> messageList = new ArrayList<MessageBean>();
	private ArrayList<MessageBean> messageList1 = new ArrayList<MessageBean>();

	private MessageListAdapter adapter;
	private MessageListAdapter adapterSystem;

	private MessageBean bean;
	private int max = 5;

	/**
	 * 判断是回复，还是系统 0=回复，1=系统
	 */
	private int type = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.mine_message);

		initViews();
		initData();
	}

	private void initViews() {
		rlt_01 = (RelativeLayout) findViewById(R.id.rlt_01);
		rlt_01.setOnClickListener(new ClickEvent());

		rlt_02 = (RelativeLayout) findViewById(R.id.rlt_02);
		rlt_02.setOnClickListener(new ClickEvent());

		tv_01 = (TextView) findViewById(R.id.tv_01);
		tv_02 = (TextView) findViewById(R.id.tv_02);

		iv_huaxian1 = (ImageView) findViewById(R.id.iv_huaxian1);
		iv_huaxian2 = (ImageView) findViewById(R.id.iv_huaxian2);

		btn_back = (Button) findViewById(R.id.btn_back);
		btn_back.setOnClickListener(new ClickEvent());

		rlv_comment = (RefreshListView) findViewById(R.id.rlv_comment);
		adapter = new MessageListAdapter(this, messageList, 0);
		rlv_comment.setAdapter(adapter);
		rlv_comment.setOnRefreshListener(this);// 刷新事件
		rlv_comment.setOnLoadMoreListener(this);// 分页加载事件

		rlv_system = (RefreshListView) findViewById(R.id.rlv_comment1);
		adapterSystem = new MessageListAdapter(this, messageList1, 1);
		rlv_system.setAdapter(adapterSystem);
		rlv_system.setOnRefreshListener(this);// 刷新事件
		rlv_system.setOnLoadMoreListener(this);// 分页加载事件
	}

	private void initData() {
		bean = new MessageBean();
		bean.setTitle("快递投诉回复");
		bean.setTime("12:05");
		bean.setDes("闲置23寸高清液晶宽屏显示器转让,有九五成新，显示效果特别好，非常清晰，一点问题没有，需要的可以联系我！");

		for (int i = 0; i < max; i++) {
			messageList.add(bean);
			messageList1.add(bean);
		}
		adapter.notifyDataSetChanged();// 更新list
		rlv_comment.onRefreshComplete();
		rlv_comment.onLoadMoreComplete(ILoadMoreViewState.LMVS_NORMAL);// 显示“查看更多”

		adapterSystem.notifyDataSetChanged();
		rlv_system.onRefreshComplete();
		rlv_system.onLoadMoreComplete(ILoadMoreViewState.LMVS_NORMAL);// 显示“查看更多”
	}

	/**
	 * 点击事件
	 * 
	 * @author Administrator
	 * 
	 */
	class ClickEvent implements View.OnClickListener {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			switch (v.getId()) {
			case R.id.btn_back: { // 返回
				finish();
			}
				break;

			case R.id.rlt_01: { // 点击回复
				tv_01.setTextColor(getResources().getColor(R.color.gold1));
				iv_huaxian1.setVisibility(View.VISIBLE);

				tv_02.setTextColor(getResources().getColor(R.color.gray02));
				iv_huaxian2.setVisibility(View.GONE);

				type = 0;

				rlv_comment.setVisibility(View.VISIBLE);
				rlv_system.setVisibility(View.GONE);

				adapter.notifyDataSetChanged();
				rlv_comment.onRefreshComplete();// 完成加载
				rlv_comment.onLoadMoreComplete(ILoadMoreViewState.LMVS_NORMAL);// 加载完毕

			}
				break;

			case R.id.rlt_02: { // 点击系统
				tv_01.setTextColor(getResources().getColor(R.color.gray02));
				iv_huaxian1.setVisibility(View.GONE);

				tv_02.setTextColor(getResources().getColor(R.color.gold1));
				iv_huaxian2.setVisibility(View.VISIBLE);

				type = 1;

				rlv_comment.setVisibility(View.GONE);
				rlv_system.setVisibility(View.VISIBLE);

				adapterSystem.notifyDataSetChanged();
				rlv_system.onRefreshComplete();// 完成加载
				rlv_system.onLoadMoreComplete(ILoadMoreViewState.LMVS_NORMAL);// 加载完毕

			}
				break;
			default:
				break;
			}
		}
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		// TODO Auto-generated method stub

	}

	@Override
	public void OnLoadMore() {
		// TODO Auto-generated method stub
		rlv_comment.onRefreshComplete();// 完成加载
		rlv_comment.onLoadMoreComplete(ILoadMoreViewState.LMVS_OVER);// 加载完毕
	}

	@Override
	public void OnRefresh() {
		// TODO Auto-generated method stub
		rlv_comment.onRefreshComplete();
	}

}
